//
//  TTHomeActivityScrollView.m
//  TaoTuo
//
//  Created by LG on 2020/10/17.
//  Copyright © 2020 刘广. All rights reserved.
//

#import "TTHomeActivityScrollView.h"
#import "TTHomeActivityViewCell.h"
#import "TTHomeADModel.h"

static NSString *cellID = @"cell_id";

@interface TTHomeActivityScrollView ()<UICollectionViewDelegate, UICollectionViewDataSource>

@property (nonatomic, strong) UICollectionView *collectionView;

@end

@implementation TTHomeActivityScrollView

- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        
        UICollectionViewFlowLayout *layout = [[UICollectionViewFlowLayout alloc] init];
        layout.itemSize = CGSizeMake(200, 120);
        layout.minimumLineSpacing = 10;
        layout.minimumInteritemSpacing = 10;
        layout.sectionInset = UIEdgeInsetsMake(0, 10, 0, 10);
        layout.scrollDirection = UICollectionViewScrollDirectionHorizontal;
        
        _collectionView = [[UICollectionView alloc] initWithFrame:self.bounds collectionViewLayout:layout];
        _collectionView.backgroundColor = UIColorHex(#F5F5F5);
        _collectionView.showsHorizontalScrollIndicator = NO;
        _collectionView.delegate = self;
        _collectionView.dataSource = self;
        [_collectionView registerClass:[TTHomeActivityViewCell class] forCellWithReuseIdentifier:cellID];
        [self addSubview:_collectionView];
        
    }
    return self;
}

- (void)setDataArray:(NSArray *)dataArray
{
    _dataArray = dataArray;
//    if (dataArray.count == 0) {
//        return;
//    }
    [self.collectionView reloadData];
}

- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
{
    return self.dataArray.count;
}

- (__kindof UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
    TTHomeActivityViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:cellID forIndexPath:indexPath];
    TTHomeADModel *model = self.dataArray[indexPath.row];
    cell.urlStr = model.ImageUrl;
    return cell;
}

- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath
{
    TTHomeADModel *model = self.dataArray[indexPath.row];
    
    [LLRouteTool skipViewControllerWIthSkipType:model.SkipType skipTarget:model.SkipTarget];
    
}

@end
